package com.awesome.designpatterndemo.proxy.proxy3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.awesome.designpatterndemo.R;
import com.awesome.designpatterndemo.proxy.proxy2.ILawsuit;
import com.awesome.designpatterndemo.proxy.proxy2.XiaoMin;
import com.awesome.sdk.util.ShowLogUtil;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Proxy3Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_proxy3);
        // 方法一，需要一个统一的动态代理类。
        ILawsuit xiaomin = new XiaoMin();
        ClassLoader loader = xiaomin.getClass().getClassLoader();
        DynamicProxy proxy = new DynamicProxy(xiaomin);
        ILawsuit lawsuit = (ILawsuit) Proxy.newProxyInstance(loader, new Class[]{ILawsuit.class}, proxy);
        lawsuit.submit();
        lawsuit.burden();
        lawsuit.defend();
        lawsuit.finish();
    }
}